#!/usr/bin/python3
# -*- coding: utf-8 -*-

import socket
import random
import string
import time

data_array_len = 20
array_data = []


def random_data(a, b):
    i = 0
    for i in range(data_array_len):
        s = random.randint(b/2, b)
        # print(s)
        chars = string.ascii_letters + string.digits
        sr = "".join( str(_)+"," for _ in range(s))
        array_data.append(sr)
    return 0


def run(times):
    sc=0
    rc=0
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('192.168.1.99', 6688))
    for i in range(times):
        print("send {} ".format(len(array_data[i%data_array_len])))
        sc+=len(array_data[i%data_array_len])
        s.send(array_data[i%data_array_len].encode('utf-8'))
        r = s.recv(8192)
        lr = len(r)
        print("recv {} ".format(lr))
        rc+= lr
        # print(s.recv(8192))
    sc += 4
    s.send(b'exit')
    # print(s.recv(8192))
    r = s.recv(8192)
    lr = len(r)
    print("recv {} ".format(lr))
    rc+= lr
    s.close()
    print("total send {} recv {}".format(sc, rc))
    

if __name__ == "__main__":
    random_data(9, 1024)
    run(9)

    chars = string.ascii_letters + string.digits
    ssr = "".join(random.choice(chars) for _ in range(111))
